package com.a0soft.gphone.aTruffleHog.wnd.phone;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.a0soft.gphone.aTruffleHog.analytic.AnalyticsUtil;
import com.a0soft.gphone.aTruffleHog.di.DeviceInfo;
import com.a0soft.gphone.aTruffleHog.gio.ui.BaseSinglePaneActivity;
import com.a0soft.gphone.aTruffleHog.util.aDebug;
import com.a0soft.gphone.aTruffleHog.wnd.stat.StatsListFrg;

public class StatsWnd extends BaseSinglePaneActivity {
    private static final String LOG_TAG = StatsWnd.class.getSimpleName();
    
    //////////////////////////////////////////// 
    @Override protected void 
    onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        if (!DeviceInfo.GetInstance(this).IsReady()) {
            finish();
            return;
        }
    }
    
    @Override protected Fragment 
    onCreatePane() 
    {
        if (aDebug.ENABLED) aDebug.d(LOG_TAG, "onCreatePane()");
        return new StatsListFrg();
    }

    @Override protected void 
    onPostCreate(Bundle bdSavedInstanceState) 
    {
        if (aDebug.ENABLED) aDebug.d(LOG_TAG, "onPostCreate()");
        super.onPostCreate(bdSavedInstanceState);
        
        getActivityHelper().setupSubActivity();
        
        AnalyticsUtil.GetInstance(this).TrackPageView(AnalyticsUtil.PAGE_STATISTICS);
    }

    @Override public void 
    onNotifyByFragment(Class<?> clsFrg, Intent it)
    {
        if (aDebug.ENABLED) {
            aDebug.d(LOG_TAG, "onNotifyByFragment()");
        }
        if (it == null) return;
        
        if (clsFrg.equals(StatsListFrg.class)) {        
            boolean bSelChangedManually = it.getBooleanExtra(StatsListFrg.EXTRA_SEL_CHANGED_MANUALLY, true);    
            if (aDebug.ENABLED) {
                aDebug.d(LOG_TAG, "  bSelChangedManually=" + bSelChangedManually);
            }        
            if (!bSelChangedManually) return;
            
            it.setClass(this, StatDetailWnd.class);
            startActivity(it);
        }
    }
}
